package com.crawler.scheduler;

import com.crawler.api.CrawlerRemover;
import com.crawler.api.Crawlerscheduler;
import com.crawler.model.CrawlerRequestInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.LinkedBlockingQueue;

@Service
@Slf4j
public class HashSetCrawlerscheduler implements Crawlerscheduler {

    private volatile LinkedBlockingQueue<CrawlerRequestInfo> unVisitedUrlQueue = new LinkedBlockingQueue<CrawlerRequestInfo>();

    @Autowired
    CrawlerRemover crawlerRemover;

    @Override
    public void push(CrawlerRequestInfo crawlerRequestInfo) {
        if(!crawlerRemover.filter(crawlerRequestInfo)){
            unVisitedUrlQueue.add(crawlerRequestInfo);
        };

    }

    @Override
    public CrawlerRequestInfo poll() {
        return unVisitedUrlQueue.poll();
    }


}
